<?php

/**
 * Created by PhpStorm.
 * User: Sergey
 * Date: 22.02.14
 * Time: 16:52
 */
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

abstract class ConnectionFactory
{
    public function query($query)
    {
        global $wpdb;
        return $wpdb->query($query);
    }

    protected function getAllRows($tableName)
    {
        global $wpdb;
        $result = $wpdb->get_results("SELECT * FROM $tableName");
        return $result;
    }

    protected function getRow($tableName, $id)
    {
        global $wpdb;
        $result = $wpdb->get_results("SELECT * FROM $tableName WHERE id=$id");
        return $result[0];
    }

    protected function removeRow($tableName, $id)
    {
        global $wpdb;
        $wpdb->delete(
            $tableName,
            array("id" => $id),
            array("%d")
        );
    }
} 